/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myapp;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Date;
import org.apache.catalina.core.ApplicationContext;

public class MySessionListener implements HttpSessionListener {

    public void sessionDestroyed(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        ServletContext sContext = session.getServletContext();
        String wasLogin = (String) session.getAttribute("login");
        if (wasLogin != null && wasLogin.equals("true")) {
            int onlineUserCount = 0;
            synchronized (sContext) {
                try {
                    onlineUserCount = (Integer) sContext.getAttribute("onlineUserCount");
                } catch (Exception e) {
                    System.err.println(e);
                }
                sContext.setAttribute("onlineUserCount", onlineUserCount - 1);
            }
        }
    }

    public void sessionCreated(HttpSessionEvent se) {
    }
}